# -*- coding: utf-8 -*-
# created on 2016/04/07

from mathsolver.functions.base.base import BaseFunction, new_latex
from mathsolver.functions.base.objects import BaseIneq, BaseBelong
from mathsolver.functions.daoshu.daoshuyunsuan import HanShuDaoShuYunSuan
from mathsolver.functions.hanshu.helper import check_inter, check_func
from mathsolver.functions.hanshu.hengchengli import HengChengLiCunZaiXing


class DiZenCunZaiQiuCan(BaseFunction):
    """函数存在单调递增区间求参数"""
    symbol = '>'

    def solver(self, *args):
        func, inter = check_func(args[0]), check_inter(args[1])

        # 求导
        deriv_func = HanShuDaoShuYunSuan().solver(func).output[0]
        self.steps.append(["", "对函数求导得：%s" % deriv_func.printing()])

        # TODO: 0.1% 可能以后要补充，求出函数定义域，单调区间是函数定义域子集求参
        # dingyi_interval = qiudingyiyu().solver(func)

        # 存在单调区间转化成不等式关系
        self.steps.append(["", "根据题意知：存在 x ∈ %s 使得 f'(x) %s 0 成立" % (new_latex(inter), self.symbol)])

        # 函数恒成立-存在型
        hcl_solver = HengChengLiCunZaiXing().solver(BaseIneq([deriv_func.expression, self.symbol, 0]), BaseBelong([deriv_func.var, "\\in", inter]))

        self.steps.extend(hcl_solver.steps)
        self.output = hcl_solver.output
        self.label.add("函数存在单调区间求参数")
        return self


class DiJianCunZaiQiucCan(DiZenCunZaiQiuCan):
    """函数存在单调递增区间求参数"""
    symbol = '<'


if __name__ == '__main__':
    pass
